24 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define D(x) cout << #x " is " << x << endl
28 typedef pair
<int, int> point
;
30 const int MAXN
= 10000;
33 point points
[2 * MAXN
];
34 int height
[MAXR
], N
, R
;
36 void solve(int distance
, int angle
) {
39 for (int r
= 0; r
<= R
; ++r
) {
43 while (j
< N
and points
[i
].first
+ angle
>= points
[j
].first
) {
44 height
[points
[j
].second
]++;
47 // from [i, j) they are correctly separated by angle
48 // printf("i = %d, j = %d, angle = %d\n", i, j, angle);
49 // printf(" "); For(k, i, j) printf("<%d, %d> ", points[k].first, points[k].second); puts("");
51 // if (height[r] > 0) {
52 // printf("height[%d] = %d\n", r, height[r]);
59 while (q
<= R
and p
+ distance
> q
) {
64 // printf("possible option from p=%d to q=%d with sum = %d\n", p, q, sum);
68 while (p
<= R
and height
[p
] == 0) p
++;
71 height
[points
[i
++].second
]--;
77 while (scanf("%d %d", &N
, &R
) == 2) {
78 if (N
== 0 and R
== 0) break;
79 for (int i
= 0; i
< N
; ++i
) {
81 scanf("%d %d", &distance
, &angle
);
82 points
[2*i
] = make_pair(angle
, distance
);
83 points
[2*i
+ 1] = make_pair(angle
+ 360, distance
);
86 sort(points
, points
+ N
);
92 scanf("%d %d", &distance
, &angle
);
93 solve(distance
, angle
);